﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WMPLib;

namespace demo02
{
    public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string playlistname = "untitled playlist";
            WMPLib.IWMPPlaylist pl;
            WMPLib.IWMPPlaylistArray plItems;
            plItems = axWindowsMediaPlayer1.playlistCollection.getByName(playlistname);
            if (plItems.count == 0)
            {
                pl = axWindowsMediaPlayer1.playlistCollection.newPlaylist(playlistname);
            } 
            else
            {
                pl = plItems.Item(0);
            }
            if(openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                foreach (string filename in openFileDialog1.FileNames)
                {
                    listitem.Items.Add(filename);
                    WMPLib.IWMPMedia item = axWindowsMediaPlayer1.newMedia(filename);
                    pl.appendItem(item);
                }
                axWindowsMediaPlayer1.currentPlaylist = pl;
                axWindowsMediaPlayer1.Ctlcontrols.play();
            }
        }
    }
}
